package com.ls.admin.service;

import com.ls.admin.dao.CompanyDao;
import com.ls.admin.dao.InternalDao;
import com.ls.admin.dao.RechargeDao;
import com.ls.admin.pojo.CompanyRecon;
import com.ls.admin.pojo.InternalRecon;
import com.ls.admin.pojo.Recharge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Optional;

@Service
public class FinanceService {

    @Autowired
    private CompanyDao companyDao;
    @Autowired
    private InternalDao internalDao;
    @Autowired
    private RechargeDao rechargeDao;


    //查看用户购买接口套餐的消费记录
    public List<CompanyRecon> checkCompanyRecon() {
        return companyDao.findAll();
    }

    //查看指定用户购买接口套餐的消费记录
    public List<CompanyRecon> findByCompanyReconid(String appid) {
        return companyDao.findByAppid(appid);
    }



    //查看用户购买接口套餐的总消费额
    public Double totalCompanyRecon() {
        List<CompanyRecon> companyRecons = companyDao.findAll();
        double total=0;
        for (CompanyRecon companyRecon : companyRecons){
            Double companyReconMoney = companyRecon.getMoney();
            total+=companyReconMoney;
        }
        return total;
    }

    //查看指定用户购买接口套餐的总消费
    public Double findByTotalCompanyRecon(String appid) {
        List<CompanyRecon> byAppid = companyDao.findByAppid(appid);
        double total=0;
        for (CompanyRecon companyRecon:byAppid) {
            Double money = companyRecon.getMoney();
            total+=money;
        }
        return total;
    }

    //查看调用第三方接口的消费记录
    public List<InternalRecon> checkInternal() {
            return internalDao.findAll();
    }

    //查看指定用户调用第三方接口的消费记录
    public List<InternalRecon> findByInternal(Integer customerid) {
        return internalDao.findByCustomerId(customerid);
    }

    //查看调用第三方接口的总消费额
    public Double totalInternal() {
        List<InternalRecon> internalRecons = internalDao.findAll();
        double total=0;
        for (InternalRecon internalRecon : internalRecons){
            Double internalReconMoney = internalRecon.getMoney();
            total+=internalReconMoney;
        }
        return total;
    }

    //查看指定用户调用第三方接口的总消费
    public Double findByTotalInternal(Integer customerid) {
        List<InternalRecon> byCustomerId = internalDao.findByCustomerId(customerid);
        double total=0;
        for (InternalRecon internalRecon:byCustomerId) {
            Double internalReconMoney = internalRecon.getMoney();
            total+=internalReconMoney;
        }
        return total;
    }


    //查看用户充值记录
    public List<Recharge> checkRecharge() {
        List<Recharge> all = rechargeDao.findAll();
        return all;
    }

    //查看指定用户充值记录
    public List<Recharge> findByRecharge(String appid) {
        List<Recharge> byAppid = rechargeDao.findByAppid(appid);
        return byAppid;
    }


    //用户充值总额
    public Double totalRecharge() {
        List<Recharge> recharges = rechargeDao.findAll();
        double total=0;
        for (Recharge recharge : recharges){
            Double rechargeAmount = recharge.getRechargeAmount();
            total+=rechargeAmount;
        }
        return total;
    }

    //查看指定用户充值总额
    public Double findByTotalRecharge(String appid) {
        List<Recharge> byAppid = rechargeDao.findByAppid(appid);
        double total=0;
        for (Recharge recharge:byAppid) {
            Double rechargeAmount = recharge.getRechargeAmount();
            total+=rechargeAmount;
        }
        return total;
    }
}
